package com.zjj.filmcommentapi.controller;

import com.zjj.filmcommentapi.utils.Result;
import org.springframework.web.bind.annotation.*;

/**
 * 处理拦截器抛出的异常
 */
@RestControllerAdvice
public class HandlerExceptionController {
    // 异常优先级问题
    // ArithmeticExcetion 继承了 RuntimeException
    // 如果一个类中既有ArithmeticException, 也有 RuntimeException
    // 如果出现 ArithmeticException, 会执行ArithmeticException
    @ExceptionHandler(value = {RuntimeException.class})
    @RequestMapping(produces = {"application/JSON"}, method = RequestMethod.POST)
    public Result dealHandlerExceptionResolver(Exception e) {
        System.out.println("处理执行时异常"+e);
        return Result.error(e.getMessage(),503);
    }

}
